
import javax.swing.JPanel;
import javax.swing.border.EmptyBorder;
import javax.swing.JLabel;
import javax.swing.JTextField;
import javax.swing.JButton;
import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;

import javax.swing.SwingConstants;
import javax.swing.JSeparator;
import java.awt.Font;
import java.util.GregorianCalendar;

import javax.swing.JTextArea;
import javax.swing.JScrollPane;
/**
 * Fenêtre de consultation d'un lecteur
 * Code du JFrame généré par Window Builder/Swing Designer.
 * @author IUT,  A.Culet 
 * @version 1.0
 */

public class VueParamQuota extends Vue {

	private static final long serialVersionUID = 1L;
	
	private JPanel contentPane;
	private JTextField textFieldPrix;
	private JTextField textFieldDuree;
	private JTextField textFieldNombre;
	
	// pour que les boutons soient des attributs, il faut faire "convert local to field"
	private JButton buttonModifier;
	private JButton buttonAnnuler;
	private JButton buttonFermer;
	
	
	/**
	 * Create the frame.
	 */
	public VueParamQuota(final Controleur controleur) {
		super(controleur);
		setTitle("Informations sur un lecteur");
		//setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE); 
		setBounds(100, 100, 452, 515);
		contentPane = new JPanel();
		this.addWindowListener (new WindowAdapter() {
			public void windowClosing (WindowEvent e) {
			getControleur().fermerVue(VueParamQuota.this);
			}
		});
		contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
		setContentPane(contentPane);
		contentPane.setLayout(null);
		
		JLabel lblNewLabel = new JLabel("Prix par jour de retard");
		lblNewLabel.setHorizontalAlignment(SwingConstants.RIGHT);
		lblNewLabel.setBounds(72, 71, 217, 15);
		contentPane.add(lblNewLabel);
		
		textFieldPrix = new JTextField();
		textFieldPrix.setBounds(167, 98, 101, 19);
		contentPane.add(textFieldPrix);
		textFieldPrix.setColumns(10);
		
		JLabel lblNewLabel_1 = new JLabel("Durée emprunt en jour");
		lblNewLabel_1.setHorizontalAlignment(SwingConstants.RIGHT);
		lblNewLabel_1.setBounds(127, 129, 165, 35);
		contentPane.add(lblNewLabel_1);
		
		textFieldDuree = new JTextField();
		textFieldDuree.setBounds(167, 161, 101, 19);
		contentPane.add(textFieldDuree);
		textFieldDuree.setColumns(10);
		
		buttonAnnuler = new JButton("Annuler");
		buttonAnnuler.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
			getControleur().fermerVue(VueParamQuota.this);}
		});
		buttonAnnuler.setBounds(84, 300, 107, 25);
		contentPane.add(buttonAnnuler);
		
		buttonModifier = new JButton("Modifier");
		buttonModifier.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				getControleur().setQuotas(textFieldPrix.getText(),textFieldDuree.getText(),textFieldNombre.getText());
			}
		});
		buttonModifier.setBounds(247, 300, 107, 25);
		contentPane.add(buttonModifier);
		
		JLabel lblNewLabel_2 = new JLabel("Nombre maximum d'emprunts par lecteur");
		lblNewLabel_2.setHorizontalAlignment(SwingConstants.RIGHT);
		lblNewLabel_2.setBounds(72, 211, 282, 17);
		contentPane.add(lblNewLabel_2);
		
		textFieldNombre = new JTextField();
		textFieldNombre.setColumns(10);
		textFieldNombre.setBounds(165, 240, 101, 19);
		contentPane.add(textFieldNombre);
		
		JLabel lblParametrageDesQuotas = new JLabel("PARAMETRAGE DES QUOTAS");
		lblParametrageDesQuotas.setFont(new Font("Dialog", Font.BOLD, 18));
		lblParametrageDesQuotas.setHorizontalAlignment(SwingConstants.CENTER);
		lblParametrageDesQuotas.setBounds(83, 12, 299, 47);
		contentPane.add(lblParametrageDesQuotas);
		
		textFieldPrix.setText(Float.toString(Controleur.PENALITE));
		textFieldDuree.setText(Integer.toString(Controleur.DUREEEMPRUNT));
		textFieldNombre.setText(Integer.toString(Controleur.MAXEMPRUNT));
		
		buttonFermer = new JButton("Fermer");
		buttonFermer.setEnabled(false);
		buttonFermer.setBounds(161, 358, 107, 25);
		contentPane.add(buttonFermer);
		buttonFermer.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				controleur.fermerVue(VueParamQuota.this);
				}
		});
	}
	
	public void setEtat (int etat){
		switch (etat) 
		{
			case initiale: {
				buttonModifier.setEnabled(true);
				buttonAnnuler.setEnabled(true);
				buttonFermer.setEnabled(false);
				textFieldPrix.setEditable(true);
				textFieldDuree.setEditable(true);
				textFieldNombre.setEditable(true);
				break;
				}
			case finale:{
				buttonModifier.setEnabled(false);
				buttonAnnuler.setEnabled(false);
				buttonFermer.setEnabled(true);
				textFieldPrix.setEditable(false);
				textFieldDuree.setEditable(false);
				textFieldNombre.setEditable(false);
				break;
				}
		}
	}
}
